package com.ethannhu.todaynews.component.api

import com.ethannhu.todaynews.component.ad.Ad
import com.ethannhu.todaynews.component.comment.Comment
import com.ethannhu.todaynews.component.content.Content
import com.ethannhu.todaynews.component.input.CodeRequest
import com.ethannhu.todaynews.component.login.Session
import com.ethannhu.todaynews.component.user.User
import com.ethannhu.todaynews.entity.Base
import com.ethannhu.todaynews.entity.BaseId
import com.ethannhu.todaynews.entity.response.DetailResponse
import com.ethannhu.todaynews.entity.response.ListResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

/**
 * 网络API
 */
interface DefaultNetworkService {
    companion object {
        fun create(): DefaultNetworkService {
            return NetWorkModule.provideRetrofit(NetWorkModule.provideOkHttpClient())
                .create(DefaultNetworkService::class.java)
        }
    }

    //内容列表
    @GET("v1/contents")
    suspend fun contents(
        @Query(value = "last") last: String?,
        @Query(value = "user_id") userId: String?,
        @Query(value = "size") size: Int,
        @Query(value = "style") style: Int? = null,
        @Query(value = "category_id") categoryId: String? = null,
    ): ListResponse<Content>

    //内容详情
    @GET("v1/contents/{id}")
    suspend fun contentDetail(@Path("id") id: String): DetailResponse<Content>

    //内容详情
    @GET("v1/users/{id}")
    suspend fun userDetail(@Path("id") id: String): DetailResponse<User>

    //评论列表
    @GET("v1/comments")
    suspend fun comments(
        @Query(value = "article_id") articleId: String?,
        @Query(value = "parent_id") parentId: String?,
        @Query(value = "page") page: Int,
        @Query(value = "size") size: Int,
    ): ListResponse<Comment>

    //登录
    @POST("v1/sessions")
    suspend fun login(
        @Body data: User
    ): DetailResponse<Session>

    //注册
    @POST("v1/users")
    suspend fun register(
        @Body data: User
    ): DetailResponse<BaseId>

    //发送验证码
    @POST("v1/codes")
    suspend fun sendCode(
        @Query(value = "style") style: Int,
        @Body data: CodeRequest
    ): DetailResponse<Base>

    //校验验证码
    @POST("v1/codes/check")
    suspend fun checkCode(
        @Body data: CodeRequest
    ): DetailResponse<Base>

    //广告
    @GET("v1/ads")
    suspend fun ads(
        @Query(value = "position") position: Int,
        @Query(value = "style") style: Int?
    ): ListResponse<Ad>

    @POST("v1/contents")
    suspend fun createContent(
        @Body data: Content
    ):DetailResponse<BaseId>

}